翻訳と辞書
Words near each other
・ External rhythm
・ External risk
・ External sector
・ External Security Manager
・ External Short Messaging Entity
・ External sorting
・ External spermatic fascia
・ External sphincter muscle of female urethra
・ External sphincter muscle of male urethra
・ External sphincter muscle of urethra
・ External storage
・ External stowage platform
・ External transcribed spacer
・ External urine collection device
・ External validity
External variable
・ External ventricular drain
・ External vertebral venous plexuses
・ External Vision System
・ External wall insulation
・ External water spray system
・ Externalism
・ Externalities of automobiles
・ Externality
・ Externalization
・ Externalizing
・ Externalizing disorders
・ Externals
・ Externism
・ Externship


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

External variable : ウィキペディア英語版
External variable

In the C programming language, an external variable is a variable defined outside any function block. On the other hand, a local (automatic) variable is a variable defined inside a function block.
== Definition, declaration and the extern keyword ==

To understand how external variables relate to the extern keyword, it is necessary to know the difference between defining and declaring a variable. When a variable is ''defined'', the compiler allocates memory for that variable and possibly also initializes its contents to some value. When a variable is ''declared'', the compiler requires that the variable be defined elsewhere. The declaration informs the compiler that a variable by that name and type exists, but the compiler does not need to allocate memory for it since it is allocated elsewhere.
The extern keyword means "declare without defining". In other words, it is a way to explicitly declare a variable, or to force a declaration without a definition. It is also possible to explicitly define a variable, i.e. to force a definition. It is done by assigning an initialization value to a variable. If neither the extern keyword nor an initialization value are present, the statement can be either a declaration or a definition. It is up to the compiler to analyse the modules of the program and decide.
A variable must be defined exactly once in one of the modules of the program. If there is no definition or more than one, an error is produced, possibly in the linking stage. A variable may be declared many times, as long as the declarations are consistent with each other and with the definition (something which header files facilitate greatly). It may be declared in many modules, including the module where it was defined, and even many times in the same module. But it is usually pointless to declare it more than once in a module.
An external variable may also be declared inside a function. In this case the extern keyword must be used, otherwise the compiler will consider it a definition of a local (automatic) variable, which has a different scope, lifetime and initial value. This declaration will only be visible inside the function instead of throughout the function's module.
The extern keyword applied to a function prototype does absolutely nothing (the extern keyword applied to a function definition is, of course, non-sensical). A function prototype is always a declaration and never a definition. Also, in standard C, a function is always external, but some compiler extensions allow a function to be defined inside a function.

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「External variable」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.